package simtester.cloud

import org.apache.tools.ant.types.FlexInteger;
import org.junit.BeforeClass;

class ServerDeployer {
	static credentials
	static authkey
	static endpoint
	
	ServerDeployer() {
		//TODO: Update SimTesterConfig.groovy to the new one used by :server
		def config = new ConfigSlurper().parse(new File('conf/SimTesterConfig.groovy').toURI().toURL())
		credentials = config.aws.credentialsfile
		authkey     = config.aws.key
		endpoint    = config.aws.endpoint
	}
	static void main(args){
		def srvDeployer = new ServerDeployer()
		def srvWar = new File(args[0])
		def aws_prop = new File(srvDeployer.credentials)
		def key_pair = new File(srvDeployer.authkey)
		def configFile = new File('conf/SimTesterConfig.groovy')
		
		def cloud = new Cloud(type:'remote', key:authkey, creds:credentials, endpoint:endpoint)
		def instance = cloud.createServer(srvpkg:srvWar, credkey:aws_prop, kp:key_pair, confFile:configFile)
        
        println "Login to server at: http://$instance.publicDnsName:8080/server"
	}
}